﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class View_TEST_GV2XLS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            System.Data.DataTable dtReport = new System.Data.DataTable();
            dtReport.Columns.Add("FLD1", typeof(System.String));
            dtReport.Columns.Add("FLD2", typeof(System.Double));
            dtReport.Columns.Add("FLD3", typeof(System.DateTime));
            System.Data.DataRow row = dtReport.NewRow();

            row[0] = "123";
            row[1] = 1234567;
            row[2] = DateTime.Now;

            dtReport.Rows.Add(row);
            GV1.DataSource = dtReport;
            GV1.DataBind();
        }
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }

    protected void btn2_click(object sender, EventArgs e)
    {
        
    }


    protected void btn1_click(object sender, EventArgs e)
    {
        Response.ClearContent();
        Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>");
        string excelFileName = "測試Excel檔案.xls";
        Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(excelFileName));
        Response.ContentType = "application/excel";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        GV1.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End(); 
    }
}
